export const DBUser = {
	getUserList() {
		let userlist = [];
		try{
			userlist = JSON.parse(window.localStorage.getItem( "userlist")) || [];
		}catch(error){
			userlist = [];
		}
		return userlist;
	},
	setUserList(userList) {
		window.localStorage.setItem( "userlist",JSON.stringify(userList));
	},
	addUser(user) {
		const userList = this.getUserList();
		userList.push(user);
		this.setUserList(userList); 
	},
	findUser({phone="",pass=""}) {
		const userlist = this.getUserList();
		return userlist.find(u =>{
			return u.phone === phone && u.pass === pass;
		})
	},
	login(user) {
		window.sessionStorage.setItem( "currUser", JSON.stringify(user));
	},
	getCurrUser() {
		try{
			return JSON.parse(window.sessionStorage.getItem( "currUser")) || {};
		}catch(error){
			return {};
		}
	},
	loginOut() { 
		window.sessionStorage.setItem("currUser","");
	}
};
